﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4.ConvertHexToDecimal
{
    class ConvertHexToDecimal
    {
           public static void Main(string[] args)
        {
            Console.WriteLine("hex number:");
            string hex = Console.ReadLine();
            Console.WriteLine("dec:");
            Console.WriteLine(ConvertToType(hex, 16)); 
        }
        
        public static int ConvertToType(string hex, int type)
        {
            int size = hex.Length;
            int pow = size - 1;
            int result = 0;
            int letter = 0;
            for (int i = 0; i < size; i++)
            {
                switch (hex[i])
                {
                    case 'A': letter = 10;
                        break;
                    case 'B': letter = 11;
                        break;
                    case 'C': letter = 12;
                        break;
                    case 'D': letter = 13;
                        break;
                    case 'E': letter = 14;
                        break;
                    case 'F': letter = 15;
                        break;
                    default: letter = int.Parse(Convert.ToString(hex[i]));
                        break;
                }
                result = result + letter * (int)(Math.Pow(type, pow));
                pow--;
            }
            return result;
        }
    }
}